package com.sum.common.bean;

import java.util.Objects;

/**
 * 通用结果类
 */
public abstract class CommonResult {
    private CommonResult() {}  // 私有构造函数

    public static final class Success extends CommonResult {
        private final String data;

        public Success(String data) {
            this.data = data;
        }

        public String getData() { return data; }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Success success = (Success) o;
            return Objects.equals(data, success.data);
        }

        @Override
        public int hashCode() {
            return Objects.hash(data);
        }
    }

    public static final class Error extends CommonResult {
        private static final Error INSTANCE = new Error();
        private Error() {}
        public static Error getInstance() { return INSTANCE; }
    }

    public static final class Exception extends CommonResult {
        private final String message;

        public Exception(String message) {
            this.message = message;
        }

        public String getMessage() { return message; }

        @Override
        public boolean equals(Object o) {
            if (this == o) return true;
            if (o == null || getClass() != o.getClass()) return false;
            Exception exception = (Exception) o;
            return Objects.equals(message, exception.message);
        }

        @Override
        public int hashCode() {
            return Objects.hash(message);
        }
    }
}
